#include <stdexcept>

using std::invalid_argument;

class Rational
{
	friend Rational operator+(const Rational& summand1, const Rational& summand2);
	friend Rational operator-(const Rational& summand1, const Rational& summand2);
	friend Rational operator*(const Rational& multiple1, const Rational& multiple2);
	friend Rational operator/(const Rational& divident, const Rational& divisor);
	friend bool operator==(const Rational& comparand1, const Rational& comparand2);
	friend bool operator!=(const Rational& comparand1, const Rational& comparand2);
	friend bool operator>(const Rational& comparand1, const Rational& comparand2);
	friend bool operator<(const Rational& comparand1, const Rational& comparand2);
	friend bool operator>=(const Rational& comparand1, const Rational& comparand2);
	friend bool operator<=(const Rational& comparand1, const Rational& comparand2);

public:
	explicit Rational(int numerator, int denominator = 0) throw(invalid_argument);

	Rational& operator+=(const Rational& summand);

	Rational& operator-=(const Rational& summand);

	Rational& operator*=(const Rational& multiple);

	Rational& operator/=(const Rational& divisor);

	Rational& operator++();
	
	Rational operator++(int);

	Rational& operator--();
	
	Rational operator--(int);

	operator double() const;

private:
	int numer_, denom_;

	int Normalize();
	
	int Gcd(int numer, int denom);
};

Rational operator+(const Rational& summand1, const Rational& summand2);

Rational operator-(const Rational& summand1, const Rational& summand2);

Rational operator*(const Rational& multiple1, const Rational& multiple2);

Rational operator/(const Rational& divident, const Rational& divisor);

bool operator==(const Rational& comparand1, const Rational& comparand2);

bool operator!=(const Rational& comparand1, const Rational& comparand2);

bool operator>(const Rational& comparand1, const Rational& comparand2);

bool operator<(const Rational& comparand1, const Rational& comparand2);

bool operator>=(const Rational& comparand1, const Rational& comparand2);

bool operator<=(const Rational& comparand1, const Rational& comparand2);
